<!DOCTYPE HTML>
<html lang="en">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="JavaScript笔试刷题小结（一）, Casey Lu&#39;s Blog">
    <meta name="description" content="">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>JavaScript笔试刷题小结（一） | Casey Lu&#39;s Blog</title>
    <link rel="icon" type="image/png" href="/medias/maozhao.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery.min.js"></script>
    
<meta name="generator" content="Hexo 4.2.0"><link rel="alternate" href="/atom.xml" title="Casey Lu's Blog" type="application/atom+xml">
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">Casey Lu's Blog</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>Index</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>Tags</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>Categories</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>Archives</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>About</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="Search" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>

<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">Casey Lu's Blog</div>
        <div class="logo-desc">
            
            Never really desperate, only the lost of the soul.
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			Index
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			Tags
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			Categories
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			Archives
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			About
		</a>
          
        </li>
        
        
    </ul>
</div>

        </div>

        
    </nav>

</header>

    
<script src="/libs/cryptojs/crypto-js.min.js"></script>
<script>
    (function() {
        let pwd = '';
        if (pwd && pwd.length > 0) {
            if (pwd !== CryptoJS.SHA256(prompt('嘻嘻嘻，访问本文章需要密码')).toString(CryptoJS.enc.Hex)) {
                alert('密码错误哦~');
                location.href = '/';
            }
        }
    })();
</script>




<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/articleimages/21.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">JavaScript笔试刷题小结（一）</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        height: calc(100vh - 250px);
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/Javascript/">
                                <span class="chip bg-color">Javascript</span>
                            </a>
                        
                            <a href="/tags/Leetcode/">
                                <span class="chip bg-color">Leetcode</span>
                            </a>
                        
                            <a href="/tags/%E7%AE%97%E6%B3%95/">
                                <span class="chip bg-color">算法</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/%E7%AC%94%E8%AF%95%E9%9D%A2%E8%AF%95/" class="post-category">
                                笔试面试
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>Publish Date:&nbsp;&nbsp;
                    2020-03-06
                </div>
                

                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>Word Count:&nbsp;&nbsp;
                    2.5k
                </div>
                

                

                
            </div>

        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <p>最近几天做的js笔试题，整理了一下，虽然前端通常不会涉及到太复杂的算法，但是在做题的过程中算法思路还是非常重要的，cc觉得刷题主要是锻炼个人的思维能力~ 不是只在乎数量</p>
<h2 id="一、钉钉前端笔试题目">一、钉钉前端笔试题目</h2>
<p><strong>1. 实现模板函数 render(template,data)</strong></p>
<blockquote>
<p>要求实现HTML的模板内置函数，示例如下：<br>
let template = ‘我是，年龄，性别’; let data = { name:‘姓名’, age: 18}<br>
Output：我是姓名，年龄18，性别undefined</p>
</blockquote>
<p>考察点：String,正则式匹配<br>
思路：实际上，使用正则匹配模板中的内容，并代替data中的内容十分简单<br>
Tips: 1) String对象的一些方法只会返回新对象，如replace(),slice(),toUpperCase()等，都不是在原数组上进行修改的2)模板中可能出现空格3)不可以从data出发考虑，因为data的某些属性并不存在，如示例中的sex</p>
<pre class=" language-language-javascript"><code class="language-language-javascript">var render = function(template, data){
  var tempStr = template.replace(/\s+/g,'')
  var resStr = tempStr.replace(/\{\{([\s\S]+?)\}\}/g,function($key, $value){
    return data[$value]
  })
  return resStr   
}
</code></pre>
<p><strong>2. 比较版本号的大小 compareVersion(version1, version2)</strong></p>
<blockquote>
<p>要求：实现一个方法，用于比较两个版本号（类似1.0.1 / 1.2.0 / 1.2 / 0.1）<br>
如果version1 &gt; version2，返回1；如果version1 &lt; version2，返回-1，其他情况返回0<br>
版本号规则<code>x.y.z</code>，x、y、z均为大于等于0的整数，至少有x位</p>
</blockquote>
<p><strong>思路</strong>： 1）先比较前两位 ，再比较后一位 2）将版本号split成为一个数组对象，之后设置优先级比较，cc最初设置的优先级利用数值，相邻两位的优先级比例100：1，但这样会出现bug，造成1.2.101 &gt; 1.3.0，所以推荐第一种方法</p>
<pre class=" language-language-javascript"><code class="language-language-javascript">var compareVersion = function(version1,version2){
  var v1Pre = parseFloat(version1)
  var v2Pre = parseFloat(version2)
  if(v1Pre > v2Pre)  return 1
  if(v1Pre < v2Pre) return -1
  //前两位版本号相同，比较最后一位
  var v1Next = version1.replace(v1pre+'.','')
  var v2Next = version2.replace(v2pre+'.','')
  if(v1Next > v2Next) return 1
  if(v1Next < v2Next) return -1
  return 0
}
</code></pre>
<p>下面是cc自己想的设置权重优先级的数值判大小的方法（版本号很大的情况不适用）</p>
<pre class=" language-language-javascript"><code class="language-language-javascript">var valueOfVersion = function(version){
  verArr = version.split('.')
  var value = 0
  var weight = 10000
  for(var item in verArr){
    value += weight * verArr[item]
    weight /= 100
  }
  return value
}
var compareVersion = function(version1, version2){
  var v1 = valueOfVersion(version1)
  var v2 = valueOfVersion(version2)
  if(v1 < v2){
    return -1
  }
  return v1>v2?1:0
}
</code></pre>
<p><strong>3. 实现随机字符串生成函数 randomStr()</strong></p>
<blockquote>
<p>要求如下：<br>
生成的随机的字符串应该以字母开头，并包含 [a-z][0-9] 这些字符。<br>
生成的字符串长度为 8。<br>
生成的字符串不能够在程序运行的生命周期中存在重复的情形。</p>
</blockquote>
<p><strong>思路</strong>: 从字符池中选择，设置生成随机的索引，生成重复字符串的几率很小p = 1/(26*36^7)</p>
<pre class=" language-language-javascript"><code class="language-language-javascript">var randomStr = function(len = 8){
  var resStr = ''
  var letterList = 'abcdefghijklmnopqrstuvwxyz'
  var strList = '0123456789abcdefghijklmnopqrstuvwxyz'
  var firstIndex = Math.floor(Math.random()*26)
  resStr += letterList[firstIndex]
  while(len-- > 1){
    var index = Math.floor(Math.random()*36)
    resStr += strList[index]
  }
  return resStr
}
</code></pre>
<h2 id="二、LeetCode题目">二、LeetCode题目</h2>
<p><strong>1. Leetcode 26：删除排序数组的重复项</strong><br>
关于JS中的数组去重，有很多方法，在排序数组中，重复的元素必然是相邻的</p>
<p>1.1 不考虑额外空间的情况</p>
<ol>
<li>利用indexOf() === -1，将不重复的元素放入新数组中</li>
</ol>
<pre class=" language-language-javascript"><code class="language-language-javascript">var removeDuplicates = function(nums){
  var newArr = []
  nums.map(function(item){
    if(newArr.indexOf(item) == -1)
      newArr.push(item)
  })
  return newArr
}
</code></pre>
<ol start="2">
<li>利用元素的indexOf()值与自身的index相同，筛选非重复项<br>
（如果是重复元素，indexOf的返回值是前面出现过的重复值，不是它本身）</li>
</ol>
<pre class=" language-language-javascript"><code class="language-language-javascript">var removeDuplicates = function(nums){
  var newArr = []
  for(var i in nums){
    if(nums.indexOf(nums[i]) === i)
      newArr.push(nums[i])
  }
  return newArr
}
</code></pre>
<ol start="3">
<li>不用indexOf，比较当前元素与newArr的尾元素（因为是有序数组，如果当前遍历项是重复项，那么必然和新数组的最后一项相同，不同才放入新数组）</li>
</ol>
<pre class=" language-language-javascript"><code class="language-language-javascript">var removeDuplicates = function(nums){
  var newArr = []
  nums.map(function(item){
    if(item !== newArr[-1])
      newArr.push(item)
  })
  return newArr
}
</code></pre>
<p>1.2 如果规定不能申请额外空间，那么我们只能在本数组上进行移动，和删除,空间复杂度O(1)</p>
<ol start="4">
<li>利用重复的元素必然相邻，把重复元素的前一个删除，这种做法数组的长度也发生了变化</li>
</ol>
<pre class=" language-language-javascript"><code class="language-language-javascript">var removeDuplicates = function(nums){
  for(var i = 0; i < nums.length - 1; i++){
    if(nums[i] === nums[i+1]){
      nums.splice(i, 1)
      i --
    }
  }
}
</code></pre>
<ol start="5">
<li>双指针,i利用索引记录需要改变的位置，j记录后一位，不相等就重新赋值新数组，指针i与j会因为重复元素的出现渐行渐远，这种做法数组的长度不变，只保证了新数组前面不重复元素的顺序，不关注后面的元素</li>
</ol>
<pre class=" language-language-javascript"><code class="language-language-javascript">var removeDuplicates = function(nums){
  if(nums.length === 0)
    return 0
  var i = 0
  for(var j = 1; j < nums.length; j++){
    if(nums[i] != nums[j]){
      nums[++i] = nums[j]
    }
  }
  return i+1  
}
</code></pre>
<p><strong>2. Leetcode 125： 判断回文字符串（忽略其他所有非数字和非字母的字符，忽略大小写差异）</strong><br>
思路：使用正则匹配式，找出字母数字的元素，验证字符串与自身反转之后的串的值是否相同</p>
<pre class=" language-language-javascript"><code class="language-language-javascript">var isPalindrome = function(s){
  var reg = /[a-zA-Z0-9]/g
  var t = s.match(reg).join('').toLowerCase()
  var s = t.split('').reverse().join()
  return t===s
}
</code></pre>
<p><strong>3. 剑指Offer面试题 10.01：合并排序的数组</strong><br>
<strong>思路</strong>: 将两个数组的前面部分都拿出来，拼在一起再进行排序</p>
<pre class=" language-language-javascript"><code class="language-language-javascript">var mergeSortedArray = function(arr1, m, arr2, n){
  A = A.slice(0,m)
  B = B.slice(0,n)
  return A.concat(B).sort()
}
</code></pre>
<p><strong>4. 剑指Offer面试题 45：把数组排成最小数</strong><br>
<strong>思路</strong>：对数组中的元素按照一定的规则排序，排序规则不是传统上数值意义的大小，而是若mn &lt; nm 则认为m &lt; n，为了防止数值拼接造成的大数范围溢出问题，在做比较的时候使用字符串作比较</p>
<pre class=" language-language-javascript"><code class="language-language-javascript">var minNumver = function(nums){
  var arrs = nums.sort(compareNum)
  return arrs.join('')
} 
// 利用字符串拼接比较两个数据的排序优先级
var compareNum = function(num1, num2){
  var str1 = num1.toString() + num2.toString()
  var str2 = num2.toString() + num1.toString()
  if(str1 < str2){
    return -1
  }
  return 1
}
</code></pre>
<p><strong>5. Leetcode 994:  烂橘子问题</strong><br>
<strong>思路</strong>：第一遍遍历，记录好橘子的个数和坏橘子的坐标（用栈的形式）<br>
第二次遍历，模拟腐烂传递的过程（在好橘子个数大于0且烂橘子坐标栈非空的时候，依次从烂橘子栈中弹出，传染周围的好橘子，更新新变坏的橘子的坐标栈，作为下一次循环的坏橘子栈，minutes ++ ）</p>
<pre class=" language-language-javascript"><code class="language-language-javascript">var orangesRotting = function(grid){
  var minutues = 0
  var freshCount = 0
  let badQue = []
  // 统计好橘子的数目和坏橘子的坐标
  for(var i = 0; i < grid.length; i++){
    for(var j = 0; j < grid[0].length; j++){
      if(grid[i][j] === 1)
        freshCount ++;
      else if(grid[i][j] === 2)
        badQue.push([i,j])
    }
  }
  // 腐烂蔓延的过程
  while(badQue.length && newFresh){
    let newBadQue = []
    while(badQue.length){
      let badOrange = badQue.shift()     
      let rottedOrange = oneRotting(newBadQue,badOrange[0],badOrange[1],grid)
      freshOrange -= rottedOrange
    }
    mintues ++
    badQue = newBadQue
  }
  if(newFresh === 0)
    return mintues
  return -1
}
// 一个坐标（i,j）的坏橘子的腐烂传染过程，rottingQue为被它感染的好橘子栈
// 函数返回新感染的橘子数目
var oneRotting = function(rottingQue,i,j,grid){
  var rottedCount = 0
  if(i - 1 > 0 && grid[i-1][j] === 1){
    rottingQue.push([i-1,j])
    rottedCount ++
    grid[i-1][j] = 2
  }
  if(i + 1< grid.length && grid[i+1][j] === 1){
    rottingQue.push([i+1,j])
    rottedCount ++
    grid[i+1][j] = 2
  }
  if(j - 1 > 0 && grid[i][j-1] === 1){
    rottingQue.push([i,j-1])
    rottedCount ++
    grid[i][j-1] = 2
  }
  if(j + 1 < grid[i].length && grid[i][j+1] === 1){
    rottingQue.push([i,j+1])
    rottedCount ++
    grid[i][j+1] = 2
  }
  return rottedCount
}
</code></pre>
<p><strong>6. Leetcode 1103：分糖果</strong><br>
思路：记录剩余的糖果数目和实际应该发的糖果数，发放的坐标根据当前手中的糖果数目决定</p>
<pre class=" language-language-javascript"><code class="language-language-javascript">var distributeCandies = function(candies, num_people){
  var candiesList = new Array(num_people)
  candiesList.fill(0, 0, num_people)
  if(candies === 0){
    return candiesList
  }
  // 初始化剩余的糖果和当前发放的糖果
  var leftCandies = candies
  var disCandies = 1
  while(leftCandies > 0){
    var index = disCandies % num_people !== 0? disCandies%num_people - 1 : num_people-1
    if(leftCandies >= disCandies){
      candiesList[index] += disCandies
      leftCandies -= disCandies
      disCandies ++
    } else { // 糖果不足，全部给当前小盆友
      candiesList[index] += leftCandies
      leftCandies = 0
    }
  }
  return candiesList
}
</code></pre>
<p><strong>7. 剑指Offer面试题 57-Ⅱ：和为s的连续正数序列</strong><br>
思路一：使用滑动窗口的方法，记录坐标在【left, right】窗口范围内的数据，比较窗口内数据和sum与target的关系决定窗口的范围：<br>
1）sum &lt; target，右边界向右滑一格  → 【left, right+1】<br>
2）sum &gt; target，左边界向右滑一格  → 【left+1, right】<br>
3）sum = target，当前窗口【】符合要求，继续右滑寻找下一窗口<br>
滑动条件：窗口最右边界right小于 target/2+1</p>
<pre class=" language-language-javascript"><code class="language-language-javascript">var findContinuousSequence = function(target){
  let res = []
  if(target < 3) return res
  // 初始化窗口[1,2]以及窗口内数据和sum
  let left = 1
  let right = 2
  let sum = left + right
  while(right < target/2 + 1){
    if(sum < target){
      right++
      sum += right
    }else if(sum > target){
      sum -= left
      left ++
    }else{
      res.push(numWindow(left,right))
      right ++
      sum += right
    }
  }
  return res
}
// 滑动窗口的内容
var numWindow = function(left, right){
  let res = []
  for(var i = left; i <= right; i++)
    res.push(i)
  return res
}
</code></pre>
<p>思路二：使用暴力法，寻找连续的数列</p>
<pre class=" language-language-javascript"><code class="language-language-javascript">var findContinuousSequence = function(target){
  let res = []
  // ES6定义内部函数，寻找以cur开始的、和为value的连续序列
  const findArr = ((cur, value)=>{
    let arr = []
    while(value > 0){
      if(curr < value){
        arr.push(cur)
        value -= cur
        cur ++
      }else{
        return;
      }
    }
    return arr
  })
  // 暴力寻找数组
  for(let i = 1; i < target/2; i++){
    let resArr = findArr(i, target)
    if(resArr)
      res.push(resArr)
  }
  return res
}
</code></pre>
<h2 id="三、阿里CBU在线笔试题">三、阿里CBU在线笔试题</h2>
<p><strong>1. 换硬币函数coinChange(coins, amount):</strong></p>
<blockquote>
<p>说明：给定不同面额的硬币 coins 和一个总金额 amount，</p>
<ul>
<li>编写一个函数来计算可以凑成总金额所需的最少的硬币个数，</li>
<li>如果没有任何一种硬币组合能组成总金额，返回 -1，</li>
<li>你可以认为每种硬币的数量是无限的。</li>
<li>示例： coinsChange([1,2,5], 11);   //3      coinChange([2, 4], 3);   // -1</li>
</ul>
</blockquote>
<p>思路一： <strong>完全背包问题</strong>，cc使用的是经典的<strong>动态规划法</strong>,记录在0-amount内，每种金额所需要的最少的硬币数目。其中，状态转移方程如下：<br>
<img src="https://img-blog.csdnimg.cn/20200306171033472.png" alt="硬币问题的状态转移方程"></p>
<pre class=" language-language-javascript"><code class="language-language-javascript">var coinChange = function(coins, amount){
  var counts = [0]
  for(var i = 1; i <= amount; i++){
    counts[i] = amount + 1
    coins.map(function(item){
      if(i >= item){
        counts[i] = Math.min(counts[i], counts[i-item]+1)
      }
    }) 
  }
  return counts[amount]>amount ? -1 : counts[amount]
}
</code></pre>
<p>同样是动态规划，还可以采用如下解法，两者相差不大：</p>
<pre class=" language-language-javascript"><code class="language-language-javascript">var coinChange = function(coins, amount){
  if(amount < 0)  return -1
  else if(amount === 0)  return 0
  // 对硬币数目数组赋初值
  const counts = new Array(amount+1)
  counts.fill(0, 0, amount+1)
  coins.map(function(item){
    if(item <= amount && item != 0){
      counts[item] = 1
    }
  })
  // 根据状态转移方程，更新不同金额下的最少硬币数目
  for(let i = 0; i < amount+1; i++){
    counts[i] = -1
    coins.map(function(item){
      if(i >= item && counts[i-item] !== -1){
        if(counts[i-item]+1 < counts[i] || counts[i] === -1){
          counts[i] = counts[i-item] + 1
        }
      }
    })
  }
  return counts[amount] // 金额为amount,所需的最少硬币数目
}
</code></pre>
<p>思路二：除了动态规划法，网上对本题还可以使用<strong>递归+回溯法</strong>、DFS，先将硬币面额按照大小排序，从每个不同面额的硬币开始DFS，而且可以通过剪枝来提高代码速度</p>
<p><strong>2. 字符串隐藏部分内容函数mask(str, char):</strong></p>
<blockquote>
<p>说明：实现一个方法，接收一个字符串和一个符号，将字符串中间四位按指定符号隐藏<br>
<em>1. 符号无指定时使用星号（*）<br>
<em>2. 接收的字符串小于或等于四位时，返回同样长度的符号串，等同于全隐藏，如 123，隐藏后是、***<br>
<em>3. 字符串长度是大于四位的奇数时，如 123456789，隐藏后是 12</em></em></em><em>789，奇数多出来的一位在末尾<br>
<em>示例：   * mask(‘alibaba’, ‘#’); // a####ba   * mask(‘85022088’); //85</em></em>**88   * mask(‘hello’); // ****o   * mask(‘abc’, ‘?’); //???</p>
</blockquote>
<pre class=" language-language-javascript"><code class="language-language-javascript">var mask = function(str, char='*'){
  let lenStr = str.length
  let resStr = ''
  while(lenStr >= 1 && lenStr <= 4){
    resStr += char
    lenStr --
  }
  if(lenStr === 0) return resStr
  let index = Math.floor((lenStr-4)/2)
  resStr = str.replace(str.slice(index,index+4),char+char+char+char)
  returen resStr
}
</code></pre>
<p><strong>3. 购物打折——价格数组转文本序列函数rangeStringify(input):</strong></p>
<blockquote>
<p>说明：我们在网上购物时常常会见到购买较多时有额外打折，这题就是把这种阶梯价给展示出来。本题即最少买5件，5到15件是12.85元，15件以上时11.36元。这种阶梯可能有多级<br>
示例：<br>
var input = [{<br>
“moqPe”: 5,<br>
“pricePe”: 12.85<br>
}, {<br>
“moqPe”: 15,<br>
“pricePe”: 11.36<br>
}]<br>
var output = rangeStringify(input);<br>
// output: “¥12.85 (5-15); ¥11.36 (≥15个)”</p>
</blockquote>
<pre class=" language-language-javascript"><code class="language-language-javascript">var rangeStringify = function(input){
  var output = ''
  for (var i = 0; i < input.length; i++){
    output += '¥'+input[i].pricePe
    if(i !== input.length-1){
      output += ' ('+input[i].moqPe+'-'+input[i+1].moqPe+');'
    }else{
      output += ' (≥'+input[i].moqPe+'个)'
    }
  }
  return output
}
</code></pre>
<p><strong>4. 平铺节点数组转嵌套树函数depthArray2Tree(input):</strong></p>
<blockquote>
<p>说明：将一个包含深度信息的节点数组转换成一棵树，要求只能遍历一次该数组<br>
输入值：TreeNode数组 TreeNode为包含title, depth(正整数，深度不限)字段的Object<br>
输出值：组装好的嵌套树，子节点挂载在对应父节点的children字段上</p>
</blockquote>
<p>下面是网络上学习的大佬的做法，cc真的无能</p>
<pre class=" language-language-javascript"><code class="language-language-javascript">function depthArray2Tree(depthArray) {
    const res = []
    for(var obj of arr){
        var keyName = ''
        for(var key in obj){
            if(key !== 'depth'){
                keyName = key;
                break;
            }
        }
        var level = obj[keyName]
        depthArray2TreeHelper(res, obj,keyName,level)
    }
    return res
  }
  var depthArray2TreeHelper = function(res,obj,keyName,level){
      if(level.length === 1){
          var pos = 0
          var currentTitle = ''
          for(var key in res[pos]){
              if(key !== "depth" && key!== "children"){
                  currentTitle = res[pos][key]
                  break
              }
          }
          while(pos < res.length && obj[keyName] >= currentTitle){
              if(obj[keyName] === currentTitle){
                  res[pos] = {children: res[pos].children, ...obj}
                  return
              }
              pos ++
              for(var key in res[pos]){
                if(key !== "depth" && key!== "children"){
                    currentTitle = res[pos][key]
                    break
                }
            }
          }
          res.splice(pos,0,obj)
          return
        }
        const currentLevel = parseInt(level.charAt(0)) - 1

        if(res[currentLevel] === null|| res[currentLevel] ===undefined){
            res[currentLevel] = {children:[]}
            res[currentLevel][keyName] = obj[keyName].slice(0,obj[keyName].length-level.length+1)
        }

        if(res[currentLevel].hasOwnProperty("children")){
            depthArray2TreeHelper(res[currentLevel].children,obj,keyName,level.slice(2))
        }else{
            const children = []
            res[currentLevel]["children"] = children
            depthArray2TreeHelper(children,obj,keyName,level.slice(2))
        }
  }
</code></pre>
<p>这段时间的题大概就是<img class="emoji" draggable="false" alt="⬆️" src="https://twemoji.maxcdn.com/v/12.1.5/72x72/2b06.png"/>这些了，后续还会整理的，加油啊，我爱学习，我爱刷题<img class="emoji" draggable="false" alt="🤘" src="https://twemoji.maxcdn.com/v/12.1.5/72x72/1f918.png"/></p>

            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        Author:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://caseylu.gitee.io" rel="external nofollow noreferrer">Casey Lu</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        Link:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://caseylu.gitee.io/2020/03/06/5-javascript-bi-shi-shua-ti-xiao-jie-yi/">https://caseylu.gitee.io/2020/03/06/5-javascript-bi-shi-shua-ti-xiao-jie-yi/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        Reprint policy:
                    </i>
                </span>
                <span class="reprint-info">
                    All articles in this blog are used except for special statements
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    reprint polocy. If reproduced, please indicate source
                    <a href="https://caseylu.gitee.io" target="_blank">Casey Lu</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>Copied successfully, please follow the reprint policy of this article</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">more</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/Javascript/">
                                    <span class="chip bg-color">Javascript</span>
                                </a>
                            
                                <a href="/tags/Leetcode/">
                                    <span class="chip bg-color">Leetcode</span>
                                </a>
                            
                                <a href="/tags/%E7%AE%97%E6%B3%95/">
                                    <span class="chip bg-color">算法</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    
    <div class="social-share" data-sites="google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">谢谢大佬的小鱼干，喵~</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>
            
        </div>
    </div>

    
        <link rel="stylesheet" href="/libs/gitalk/gitalk.css">
<link rel="stylesheet" href="/css/my-gitalk.css">

<div class="card gitalk-card" data-aos="fade-up">
    <div class="comment_headling" style="font-size: 20px; font-weight: 700; position: relative; left: 20px; top: 15px; padding-bottom: 5px;">
        <i class="fas fa-comments fa-fw" aria-hidden="true"></i>
        <span>评论</span>
    </div>
    <div id="gitalk-container" class="card-content"></div>
</div>

<script src="/libs/gitalk/gitalk.min.js"></script>
<script>
    let gitalk = new Gitalk({
        clientID: 'b739596984975414aa79',
        clientSecret: 'c5792bc3376f951910111f232176fbadfa919286',
        repo: 'L0ittle.github.io',
        owner: 'L0ittle',
        admin: "L0ittle",
        id: '2020-03-06T20-56-20',
        distractionFreeMode: false  // Facebook-like distraction free mode
    });

    gitalk.render('gitalk-container');
</script>
    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;Previous</div>
            <div class="card">
                <a href="/2020/03/07/6-niu-ke-wang-qian-duan-zhi-shi-shua-ti-xiao-jie/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/articleimages/36.jpg" class="responsive-img" alt="牛客网前端知识点小结(一)">
                        
                        <span class="card-title">牛客网前端知识点小结(一)</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            前端知识笔记
之前在牛客网做练习时关于前端知识的笔记，写在OneNote上很琐碎，今天整理了下，以后系统地、有条理的总结。



                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2020-03-07
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/" class="post-category">
                                    技术分享
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Javascript/">
                        <span class="chip bg-color">Javascript</span>
                    </a>
                    
                    <a href="/tags/CSS/">
                        <span class="chip bg-color">CSS</span>
                    </a>
                    
                    <a href="/tags/HTML/">
                        <span class="chip bg-color">HTML</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                Next&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2020/03/04/4-a-li-ding-ding-qian-duan-shi-xi-yi-mian/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/articleimages/29.jpg" class="responsive-img" alt="阿里钉钉前端实习一面">
                        
                        <span class="card-title">阿里钉钉前端实习一面</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            一、钉钉面试问题
首先做一下你的自我介绍以及你简历上的项目，以及难点创新点（介绍了大概5min）
(在我做介绍的过程中，面试官记录了他想要问的问题 at same time)
回答的项目相对之前清晰，但还是有卡顿，多熟悉复盘项目真的重要！

                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2020-03-04
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E7%AC%94%E8%AF%95%E9%9D%A2%E8%AF%95/" class="post-category">
                                    笔试面试
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Javascript/">
                        <span class="chip bg-color">Javascript</span>
                    </a>
                    
                    <a href="/tags/CSS/">
                        <span class="chip bg-color">CSS</span>
                    </a>
                    
                    <a href="/tags/HTML/">
                        <span class="chip bg-color">HTML</span>
                    </a>
                    
                    <a href="/tags/Vue/">
                        <span class="chip bg-color">Vue</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('100')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + 'From: Casey Lu&#39;s Blog<br />'
            + 'Author: Casey Lu<br />'
            + 'Link: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>


<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


<!-- 代码块折行 -->

<style type="text/css">
code[class*="language-"], pre[class*="language-"] { white-space: pre !important; }
</style>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;TOC</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>



    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/libs/aplayer/APlayer.min.css">
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="4892766072"
                   fixed='true'
                   autoplay='false'
                   theme:='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/libs/aplayer/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>

    
    <div class="container row center-align" style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            <span id="year">2020</span>
            <a href="https://caseylu.gitee.io" target="_blank">Casey Lu</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                class="white-color">63.2k</span>&nbsp;字
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/L0ittle" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:caseylu119@163.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=1351238945" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 1351238945" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;Search</span>
            <input type="search" id="searchInput" name="s" placeholder="Please enter a search keyword"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
});
</script>
    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    <!-- Global site tag (gtag.js) - Google Analytics -->


    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    

    

    
    
    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
